/**
* Storage 二次封装
* @author LoneWolf
*/

import config from '@/config/index'
const nameSpace = config.nameSpace

const storage = {
    getItem (key) {
        return this.getAll()[key]
    },
    setItem (key, val) {
        let storage = this.getAll()
        storage[key] = val
        localStorage.setItem(nameSpace, JSON.stringify(storage))
    },
    removeItem (key) {
        let storage = this.getAll()
        delete storage[key]
        localStorage.setItem(nameSpace, JSON.stringify(storage))
    },
    getAll () {
        return JSON.parse(localStorage.getItem(nameSpace) || '{}')
    },
    clearAll () {
        localStorage.setItem(nameSpace, '')
    }
}

export default storage